package cn.com.selfsoft.smartcity.core.repository;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 2019-3-14 15:57:25
 * 自定义更新时间字段，由mybatisplus管理
 */
@Component
public class MybatisAutoFillHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        setFieldValByName("createdAt", LocalDateTime.now(),metaObject);
        setFieldValByName("lastUpdatedAt",LocalDateTime.now(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName("lastUpdatedAt",LocalDateTime.now(),metaObject);
    }
}